var KOC = require("koc.common.utils");
var fs = require("fs");
var DALFactory = require("../../lib/dal/dal-factory");
var CommonUtils = require("../../lib/common-utils");

module.exports = {
    //房间管理主页
    Main: function (req, res, callback) {
        res.render("room-manage/main", callback);
    },
    //房间管理
    Info_Manage: {
        /////////////////////////////
        //艺人房间列表
        ////////////////////////////
        RoomList: function (req, res, callback) {
            res.render("room-manage/info-manage/roomlist", callback);
        },
        /////////////////////////////
        //冻结/解冻房间
        ////////////////////////////
        Freeze_Melt: function (req, res, callback) {
            var _PageData = {
                flag: 0,
                User_ID: KOC.StringUtils.ToInt(req.params.id, -1)
            };
            if (_PageData.User_ID <= 0) {
                CommonUtils.Common.PageScript_PageData(res, _PageData);
                res.render("room-manage/info-manage/freeze-melt", callback);
                return;
            }
            KOC.Async.parallel([
                //用户信息列表
                function (callback) {
                    DALFactory.User.User_Info.Info(_PageData.User_ID, function (retValue) {
                        if (retValue.hasError) {
                            callback(retValue);
                            return;
                        }
                        _PageData.User_ID = retValue.returnObject.User_ID;
                        _PageData.NickName = retValue.returnObject.NickName;
                        _PageData.Sex = retValue.returnObject.Sex;
                        _PageData.RealName = retValue.returnObject.RealName;
                        //_PageData.Email = retValue.returnObject.Email;
                        //_PageData.Phone = retValue.returnObject.Phone;
                        _PageData.VIP = retValue.returnObject.VIP && (!retValue.returnObject.VIP_Expire || KOC.Moment().isBefore(retValue.returnObject.VIP_Expire));
                        _PageData.EXP = retValue.returnObject.EXP;
                        _PageData.Level = CommonUtils.User.Level.fnLevel(retValue.returnObject.EXP);
                        _PageData.Coin = retValue.returnObject.Coin;
                        _PageData.Coin_Today = retValue.returnObject.Coin_Today;
                        _PageData.Coin_Week = retValue.returnObject.Coin_Week;
                        _PageData.Coin_Month = retValue.returnObject.Coin_Month;
                        _PageData.Coin_Year = retValue.returnObject.Coin_Year;
                        _PageData.Coin_Total = retValue.returnObject.Coin_Total;
                        _PageData.Beans = retValue.returnObject.Beans;
                        _PageData.Beans_Today = retValue.returnObject.Beans_Today;
                        _PageData.Beans_Week = retValue.returnObject.Beans_Week;
                        _PageData.Beans_Month = retValue.returnObject.Beans_Month;
                        _PageData.Beans_Year = retValue.returnObject.Beans_Year;
                        _PageData.Beans_Total = retValue.returnObject.Beans_Total;
                        _PageData.Fans = retValue.returnObject.Fans;
                        _PageData.Attention = retValue.returnObject.Attention;
                        _PageData.IsAnchor = retValue.returnObject.IsAnchor;
                        _PageData.IsFamily = retValue.returnObject.IsFamily;
                        _PageData.Login_Count = retValue.returnObject.Login_Count;
                        _PageData.Login_This_Date = retValue.returnObject.Login_This_Date;
                        _PageData.Create_Date = retValue.returnObject.Create_Date;
                        //_PageData.Status = retValue.returnObject.Status;

                        callback(null);
                    });
                },
                // 艺人信息列表
                function (callback) {
                    DALFactory.User.User_Anchor.Info(_PageData.User_ID, function (retValue) {
                        if (retValue.hasError) {
                            callback(retValue);
                            return;
                        }
                        _PageData.Family_Commission = retValue.returnObject.Family_Commission;
                        _PageData.RoomName = retValue.returnObject.RoomName;
                        _PageData.RoomWelcome = retValue.returnObject.RoomWelcome;
                        _PageData.Tags = retValue.returnObject.Tags;
                        _PageData.Anchor_EXP = retValue.returnObject.EXP;
                        _PageData.Pomelo = retValue.returnObject.Pomelo;
                        _PageData.Pomelo_Today = retValue.returnObject.Pomelo_Today;
                        _PageData.Pomelo_Week = retValue.returnObject.Pomelo_Week;
                        _PageData.Pomelo_Month = retValue.returnObject.Pomelo_Month;
                        _PageData.Pomelo_Year = retValue.returnObject.Pomelo_Year;
                        _PageData.Live = retValue.returnObject.Live;
                        _PageData.Live_StartTime = retValue.returnObject.Live_StartTime;
                        _PageData.Live_Order_No = retValue.returnObject.Live_Order_No;
                        _PageData.Live_Duration_Total = retValue.returnObject.Live_Duration_Total;
                        _PageData.IDCard = retValue.returnObject.IDCard;
                        _PageData.Anchor_Phone = retValue.returnObject.Phone;
                        _PageData.Anchor_Email = retValue.returnObject.Email;
                        _PageData.QQ = retValue.returnObject.QQ;
                        _PageData.Network = retValue.returnObject.Network;
                        _PageData.Account_BankName = retValue.returnObject.Account_BankName;
                        _PageData.Account_BankFullName = retValue.returnObject.Account_BankFullName;
                        _PageData.Account_RealName = retValue.returnObject.Account_RealName;
                        _PageData.Account_CardNo = retValue.returnObject.Account_CardNo;
                        _PageData.List_Order = retValue.returnObject.List_Order;
                        _PageData.Anchor_Create_Date = retValue.returnObject.Create_Date;
                        _PageData.Anchor_Status = retValue.returnObject.Status;
                        _PageData.Anchor_Level = retValue.returnObject.Level;
                        _PageData.Level_Next = retValue.returnObject.Level_Next;
                        _PageData.EXP_Next = retValue.returnObject.EXP_Next;
                        _PageData.EXP_Difference = retValue.returnObject.EXP_Difference;

                        callback(null);
                    });
                }
            ], function (retValue) {
                if (retValue) {
                    _PageData.flag = retValue.message;
                    CommonUtils.Common.PageScript_PageData(res, _PageData);
                    res.render("room-manage/info-manage/freeze-melt", callback);
                    return;
                }
                CommonUtils.Common.PageScript_PageData(res, _PageData);
                res.render("room-manage/info-manage/freeze-melt", callback);
            })
        },
        //////////////////////////////
        //消息列表
        ////////////////////////////
        NewsList: function (req, res, callback) {
            res.render("room-manage/info-manage/newslist", callback);
        },
        /////////////////////////////
        //开播记录
        ////////////////////////////
        SignList: function (req, res, callback) {
            res.render("room-manage/info-manage/signlist", callback);
        }
    }
};